package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.gdms.model.User;
import com.zr.gdms.service.AddStudentService;
import com.zr.gdms.service.LoginService;
import com.zr.gdms.serviceimpl.AddStudentServiceimpl;
import com.zr.gdms.serviceimpl.LoginServiceImpl;

public class AddStudentController extends HttpServlet {
	AddStudentService ass=new AddStudentServiceimpl();
	LoginService ls = new LoginServiceImpl();
			@Override
			protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
				// TODO Auto-generated method stub
				doPost(req, resp);
			}
			@Override
			protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// TODO Auto-generated method stub
				HttpSession session =req.getSession();
				String sname=req.getParameter("sname");
				String sage=req.getParameter("sage");
				String ssex=req.getParameter("ssex");
				String sdepart=req.getParameter("sdepart");
				String stel=req.getParameter("stel");
				String sstate=req.getParameter("sstate");
				String uname=req.getParameter("uname");
				String upsw=req.getParameter("upsw");
				PrintWriter pw = resp.getWriter();
				boolean flag1 = ass.userInsertstuval(uname, upsw);
				User u = ls.findUserByUnameAndUpsw(uname, upsw);
				int uid = u.getUid();
				boolean  flag2= ass.Insertstuval(sname, sage, ssex, sdepart, stel, sstate,uid);
				if(flag1){					
					if(flag2){
						pw.write("1");
					} else {
						pw.write("0");
					}
				} else {
					pw.write("0");
				}
				pw.flush();
				pw.close();
			}
}
